package macro;

import star.common.*;
import star.base.neo.*;

public class CreateresistanceA1 extends StarMacro {

    public void execute() {
        for (int i = 2; i <= 24; i++) {
            execute0(i);
        }
    }

    private void execute0(int i) {
        String definition = generateResistanceDefinition(i);

        Simulation simulation_0 = getActiveSimulation();
        UserFieldFunction userFieldFunction_5 = simulation_0.getFieldFunctionManager().createFieldFunction();
        UserFieldFunction userFieldFunction_3 = (UserFieldFunction) simulation_0.getFieldFunctionManager().getFunction("resistance A1");

        userFieldFunction_5.copyProperties(userFieldFunction_3);
        userFieldFunction_5.setPresentationName("resistance A" + i + " \u526F\u672C");
        userFieldFunction_5.setDefinition(definition);
        userFieldFunction_5.setPresentationName("resistance A" + i);
        userFieldFunction_5.setFunctionName("resistance A" + i);
    }

    private String generateResistanceDefinition(int i) {
        int[] thresholds = {99, 95, 90, 80, 70, 60, 50, 40, 30, 20, 10, 5, 3};
        int[] thresholds2 = {100, 100, 95, 90, 80, 70, 60, 50, 40, 30, 20, 10, 5};

        StringBuilder result = new StringBuilder();
        for (int j = 0; j < thresholds.length; j++) {
            int threshold = thresholds[j];
            int threshold2 = thresholds2[j];
            result.append("${Soc_report}>")
                  .append(threshold)
                  .append("?(interpolateTable(@Table(\"DCR\"),\"Temp\",LINEAR, \"SOC")
                  .append(threshold2)
                  .append("\", ${cellTemp A")
                  .append(i)
                  .append("}-273.15)):")
                  .append("\n"); // 换行
        }

        result.append("(interpolateTable(@Table(\"DCR\"),\"Temp\",LINEAR, \"SOC0\", ${cellTemp A")
              .append(i)
              .append("}-273.15))")
              .append("\n"); // 换行

        return result.toString();
    }
}
